package com.example.zhihuhelpapp.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class FormatUtils {
    public static String format_ = "yyyy-MM-dd HH:mm:ss";
    public static long anHour = 60 * 60 * 1000;

    public static String longToDateCommon(long l, String style) {
        SimpleDateFormat sdf = new SimpleDateFormat(style);
        String format = sdf.format(new Date(l));
        return format;
    }

    public static long strToLong(String date, String style) {
        SimpleDateFormat sdf = new SimpleDateFormat(style);
        try {
            return sdf.parse(date).getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return System.currentTimeMillis();
    }

    public static String getDetailTime() {
        return longToDateCommon(System.currentTimeMillis(), format_);
    }

    public static Date getStartTime() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime();
    }

    public static Date getEndTime() {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.HOUR, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime();
    }
}
